var prefix = ctx + "manage/questionBank"

$(function () {
    var columns = [{
        checkbox: true
    },
        {
            field: 'id',
            title: '主键'
        },
        {
            field: 'qbLevel',
            title: '难度等级'
        },
        {
            field: 'qbContent',
            title: '题目'
        },
        {
            field: 'qbValueA',
            title: '选项A'
        },
        {
            field: 'qbValueB',
            title: '选项B'
        },
        {
            field: 'qbValueC',
            title: '选项C'
        },
        {
            field: 'qbValueD',
            title: '选项D'
        },
        {
            field: 'qbResult',
            title: '答案'
        },
        {
            field: 'qbAnalysis',
            title: '解析'
        },
        {
            field: 'createTime',
            title: '创建时间'
        },
        {
            title: '操作',
            align: 'center',
            formatter: function (value, row, index) {
                var actions = [];
                actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
                return actions.join('');
            }
        }];
    var url = prefix + "/list";
    $.initTable(columns, url);
});

/*成语题库-新增*/
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增成语题库", url);
}

/*成语题库-修改*/
function edit(id) {
    var url = prefix + '/edit/' + id;
    layer_showAuto("修改成语题库", url);
}

// 单条删除
function remove(id) {
    $.modalConfirm("确定要删除选中成语题库吗？", function () {
        _ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
    var rows = $.getSelections("id");
    if (rows.length == 0) {
        $.modalMsg("请选择要删除的数据", "warning");
        return;
    }
    $.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function () {
        _ajax(prefix + '/batchRemove', {"ids": rows}, "post");
    });
}

var uploadFiles =  document.getElementById("fileUpload");
var  file;
uploadFiles.addEventListener('change', function(event) {
     file = event.target.files[0]; // 获取文件对象

});
//文件上传
function uploadFile() {
    //当文件被选中时，获取文件对象
    var formData = new FormData();
    formData.append('file', file); // this.files[0]是文件对象
    _ajax_file(prefix+'/upload',formData);
}
